Skip to content

Fix face detection failures for non-photorealistic images#1037

Open
cab66420 wants to merge 1 commit intoOpenTalker:mainfrom
cab66420:fix/face-detection-fallback
Open

Fix face detection failures for non-photorealistic images#1037
cab66420 wants to merge 1 commit intoOpenTalker:mainfrom
cab66420:fix/face-detection-fallback

Conversation

@cab66420
Copy link
Copy Markdown

Summary

  • ****: Fixed invalid syntax (Python 3 requires ). Added a graceful fallback when landmark detection returns or empty in preprocess mode - returns the full image dimensions as / () so the pipeline continues without a detected face.

  • ****: raises when returns an empty array (no face found). Added to the existing handler so it falls back to keypoints, which already handles gracefully via the check.

Motivation

When using with anime, illustrated, or stylized portrait images, real face detectors (RetinaFace / dlib) frequently return no detections. Before this fix, the pipeline crashed with either a (from the invalid statement) or an unhandled . These changes allow SadTalker to process non-photorealistic source images without errors.

Test plan

  • Run with an anime/illustrated source image and confirm it completes without or
  • Run with a real photo to confirm existing behaviour is unchanged
  • Confirm generated video plays correctly

When using --preprocess full with anime/illustrated images, face
detection fails at two points and crashes with unhelpful errors:

1. croper.py: `raise 'string'` was invalid Python 3 syntax and
   lm=None check didn't handle the full-mode case. Now returns the
   full image as crop/quad ([0,0,W,H]) so processing continues
   without a detected face.

2. extract_kp_videos_safe.py: `bboxes[0]` raises IndexError when
   detect_faces() returns an empty array. Added IndexError to the
   existing TypeError handler so it falls back to -1 keypoints,
   which preprocess.py already handles gracefully.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant